import random
from datetime import datetime

# 优惠券列表
coupon_list = ["无优惠", "空调8折", "冰箱9折", "洗衣机95折", "电视9折", "电脑85折", "手机9折", "平板85折", "耳机9折", "手表95折"]
# 随机抽取一张优惠券
def draw_coupon():
    return random.choice(coupon_list)

# 打印购物小票
def print_receipt(shopping_time, balance, quantity, total_value):
    print("购物小票：")
    print(f"购物时间：{shopping_time}")
    print(f"卡余额：{balance}元")
    print(f"购物数量：{quantity}件")
    print(f"购买总商品的价值：{total_value}元")
    print("-" * 40)

# 退货功能
def return_goods(goods_name, my_goods_list, goods_list, goods_price, total_goods_price, total_money):
    if goods_name in my_goods_list:
        my_goods_list.remove(goods_name)
        total_goods_price -= goods_price
        total_money += goods_price
        print(f"{goods_name}已退回，您的账户余额为：{total_money}")
    else:
        print(f"{goods_name}不在您的购物列表中，无法退货。")


# 主函数
def ShoopingV2():
    global goods_price
    global total_goods_price
    global total_money
    global temp_money
    coupon = draw_coupon()
    print(f"欢迎来到ShoopingV2.0系统！*****您抽到的优惠券是：{coupon}\n")
    total_money = 10000
    total_goods_price = 0
    goods_list = ["空调", "冰箱", "洗衣机", "电视", "电脑", "手机", "平板", "耳机", "手表"]
    my_goods_list = []

    print("商品列表：", goods_list)
    print("我的购物列表：", my_goods_list)
    print("我的账户余额为：", total_money)
    print("-" * 40)

    while total_money > 0:
        goods_name = input("请输入您要购买的商品名称（输入'q'退出，输入'退'退货）：")
        if goods_name == 'q':
            break
        elif goods_name == '退':
            return_goods(input("请输入要退货的商品名称："), my_goods_list, goods_list, goods_price, total_goods_price, total_money)
            continue
        elif goods_name not in goods_list:
            print("您输入的商品名称不存在，请重新输入！")
            continue

        goods_price = {"空调": 1000, "冰箱": 2000, "洗衣机": 1500, "电视": 5000, "电脑": 10000, "手机": 2000, "平板": 1500, "耳机": 1000, "手表": 1500}.get(goods_name, 0)
        # my_goods_list.append(goods_name)
        # total_goods_price += goods_price

        if  goods_name == "空调":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "空调8折":
                goods_price *= 0.8
                print("使用空调8折优惠券，空调价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif goods_name == "冰箱":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "冰箱9折":
                goods_price *= 0.9
                print("使用冰箱9折优惠券，冰箱价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "洗衣机":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "洗衣机95折":
                goods_price *= 0.95
                print("使用洗衣机95折优惠券，洗衣机价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "电视":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "电视9折":
                goods_price *= 0.9
                print("使用电视9折优惠券，电视价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "电脑":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "电脑85折":
                goods_price *= 0.85
                print("使用电脑85折优惠券，电脑价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "手机":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "手机9折":
                goods_price *= 0.9
                print("使用手机9折优惠券，手机价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "平板":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "平板85折":
                goods_price *= 0.85
                print("使用平板85折优惠券，平板价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif  goods_name == "耳机":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "耳机9折":
                goods_price *= 0.9
                print("使用耳机9折优惠券，耳机价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        elif goods_name == "手表":
            if total_money < goods_price:
                print("您的账户余额不足，请充值！")
                break
            elif coupon == "手表95折":
                goods_price *= 0.95
                print("使用手表95折优惠券，手表价格为：", goods_price)
                total_money -= goods_price
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
            else:
                print("没有可用的优惠券！")
                total_money -= goods_price
                print("空调价格为：", goods_price)
                print(f"您已成功购买{goods_name}，您的账户余额为：{total_money}")
                my_goods_list.append(goods_name)
                total_goods_price += goods_price
        else:
            print("没有可用的优惠券！")



    shopping_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print_receipt(shopping_time, total_money, len(my_goods_list), total_goods_price)
    print("您的购物清单：", my_goods_list)
    print("欢迎下次使用ShoopingV2.0系统！")
    print("-" * 40)

ShoopingV2()